package com.kofigyan.stateprogressbarsample.not_stateprogressbar.custom;

import com.kofigyan.stateprogressbar.utils.AttrSetUtils;
import com.kofigyan.stateprogressbar.utils.LogUtil;
import com.kofigyan.stateprogressbarsample.ResourceTable;
import ohos.agp.components.*;
import ohos.app.Context;

public class UserDetailsView extends DependentLayout implements Component.ClickedListener {

    private Text mDetailLabel;
    private Text mDetailValue;
    private OnUserDetailClickListener onUserDetailClickListener;

    public UserDetailsView(Context context) {
        this(context, null);
    }

    public UserDetailsView(Context context, AttrSet attrSet) {
        this(context, attrSet, null);
    }

    public UserDetailsView(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        init(context, attrSet);
    }

    private void init(Context context, AttrSet attrSet) {
        LayoutScatter.getInstance(context)
                .parse(ResourceTable.Layout_view_user_details, this, true);
        mDetailLabel = (Text) findComponentById(ResourceTable.Id_tvLabel);
        mDetailValue = (Text) findComponentById(ResourceTable.Id_tvValue);

        final String detailsLabel = AttrSetUtils.optString(attrSet, "detailsLabel", "");
        final String detailsValue = AttrSetUtils.optString(attrSet, "detailsValue", "");

        setDetailLabel(detailsLabel);
        setDetailValue(detailsValue);

        setClickedListener(this);
    }

    public void setDetailLabel(String label) {
        this.mDetailLabel.setText(label);
    }

    public void setDetailValue(String value) {
        this.mDetailValue.setText(value);
    }

    @Override
    public void onClick(Component component) {
        if (onUserDetailClickListener != null) {
            onUserDetailClickListener.onUserDetailClickListener(this);
        }
    }

    public void setOnUserDetailClickListener(OnUserDetailClickListener onUserDetailClickListener) {
        this.onUserDetailClickListener = onUserDetailClickListener;
    }

    public interface OnUserDetailClickListener {
        public void onUserDetailClickListener(Component v);
    }
}
